#include<iostream>
using namespace std;
class country
{
    public:
    int num;
    int getings;
    int counts;
};
int main()
{
    int n;
    cin>>n;
    country cty[n+1];//直接使用数字代表国家
    for(int i=1;i<n+1;i++)
    {
        cty[i].counts=0;//其实可以直接类初始化
        cty[i].getings=0;
        cty[i].num=i;
    }
    for(int i=1;i<n+1;i++)
    {
        int *in=new int;
        cin>>*in;
        cty[i].counts+=*in;
        for(int j=0;j<*in;j++)
        {
            int *id=new int;
            cin>>*id;
            cty[*id].counts++;
            int *inin=new int;
            cin>>*inin;//
            cty[i].getings+=*inin;
            cty[*id].getings-=*inin;
            delete id;
            delete inin;
        }
        delete in;
    }
    for(int i=1;i<n+1;i++)
    {
        for(int j=1;j<n;j++)
        {
            if(cty[j].getings==cty[j+1].getings&&cty[j].counts==cty[j+1].counts&&cty[j].num>cty[j+1].num)
            {
                country *p=new country;
                *p=cty[j];
                cty[j]=cty[j+1];
                cty[j+1]=*p;
                delete p;
            }
            /////
            else if(cty[j].getings==cty[j+1].getings&&cty[j].counts<cty[j+1].counts)
            {
                country *p=new country;
                *p=cty[j];
                cty[j]=cty[j+1];
                cty[j+1]=*p;
                delete p;
            }   
            else if(cty[j].getings<cty[j+1].getings)
            {
                country *p=new country;
                *p=cty[j];
                cty[j]=cty[j+1];
                cty[j+1]=*p;
                delete p;
            }    
        }
    }
    for(int i=1;i<n+1;i++)
    {
        cout<<cty[i].num<<" "<<cty[i].getings<<endl;
    }
    return 0;
////


////

    
}
